package org.zizi.db.plan.plan;

import java.sql.Types;
import java.util.HashMap;
import java.util.Map;

import org.zizi.db.charset.CharsetEncoder;
import org.zizi.db.column.AbstractColumnReader;
import org.zizi.db.column.ColumnReader;
import org.zizi.db.column.impl.BigIntColumnReader;
import org.zizi.db.column.impl.BlobColumnReader;
import org.zizi.db.column.impl.BooleanColumnReader;
import org.zizi.db.column.impl.ClobColumnReader;
import org.zizi.db.column.impl.DateColumnReader;
import org.zizi.db.column.impl.DoubleColumnReader;
import org.zizi.db.column.impl.IntegerColumnReader;
import org.zizi.db.column.impl.NumericColumnReader;
import org.zizi.db.column.impl.VarcharColumnReader;
import org.zizi.db.plan.ResultPlan;

public class OracleResultPlan extends ResultPlan
{
	private static Map<Integer, AbstractColumnReader> readers = new HashMap<Integer, AbstractColumnReader>();
	static
	{
		readers.put(Types.BOOLEAN, new BooleanColumnReader());
		readers.put(Types.BIT, new BooleanColumnReader());
		readers.put(Types.DOUBLE, new DoubleColumnReader());
		readers.put(Types.REAL, new DoubleColumnReader());
		readers.put(Types.INTEGER, new IntegerColumnReader());
		readers.put(Types.BIGINT, new BigIntColumnReader());
		readers.put(Types.NUMERIC, new NumericColumnReader());
		readers.put(Types.CLOB, new ClobColumnReader());
		readers.put(Types.BLOB, new BlobColumnReader());
		readers.put(Types.BINARY, new BlobColumnReader());
		readers.put(Types.VARBINARY, new BlobColumnReader());
		readers.put(Types.LONGVARBINARY, new BlobColumnReader());
		readers.put(Types.VARCHAR, new VarcharColumnReader());
		readers.put(Types.LONGVARCHAR, new VarcharColumnReader());
		readers.put(Types.CHAR, new VarcharColumnReader());
		readers.put(Types.DATE, new DateColumnReader());
		readers.put(Types.TIME, new DateColumnReader());
		readers.put(Types.TIMESTAMP, new DateColumnReader());
	}
	
	public OracleResultPlan(CharsetEncoder charset)
	{
		super(charset);
	}
	
	protected ColumnReader getColumnReader(int type)
	{
		AbstractColumnReader reader = readers.get(type);
		if (reader != null) reader.setCharset(charset);
		
		return reader;
	}
}
